import static org.junit.Assert.*;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.FormatterClosedException;

import org.junit.Test;


public class Module2 {
	static private Formatter output; // object used to output text to file
	@Test
	public void createFile(String file, ArrayList<Value> availableValues, ArrayList<Value> parsedValues) 
	   {
	      try
	      {
	        output = new Formatter(file);
	      } // end try
	      catch ( SecurityException securityException )
	      {
	         System.err.println(
	            "You do not have write access to this file." );
	         System.exit( 1 );
	      } // end catch
	      catch ( FileNotFoundException filesNotFoundException )
	      {
	         System.err.println( "Error creating file." );
	         System.exit( 1 );
	      } // end catch
	          try // output values to file
	         { 
	              // write new record
	              output.format("Topological Sort For\n");
	              for(Value v : availableValues){                                         
	               if(v.dependencies!= null){
	                   output.format( "%s: ", v.getName());
	                   int dependenciesValueSize = v.dependencies.size();
	                   for(Value vDep : v.dependencies){                       
	                       if(dependenciesValueSize > 1)
	                           output.format( "%s, ", vDep.getName());
	                       else output.format( "%s\n", vDep.getName());
	                       --dependenciesValueSize;                       
	                   }                                    
	               }
	               }
	               output.format( "is\n\n");        
	               for(Value p : parsedValues)    
	                   output.format( "%s\n", p.getName());                                              
	                              
	         } // end try
	         catch ( FormatterClosedException formatterClosedException )
	         {
	            System.err.println( "Error writing to file." );
	            return;
	         } // end catch
	       if ( output != null )
	         output.close();
	   } // end method creatFile
}